$(document).ready(function () {
    FB.init({
        appId: '225056930986230',
        status: true,
        cookie: true,
        xfbml: true
    });


//    FB.getLoginStatus(function (status) {
//        console.log("Status login: ", status);
//        FB.login(function (response) {
//            console.log("Info login: ", response);
//            var user_id = response.authResponse.userID;
//            FB.api('me/likes/175087535966290', function (data) {
//                console.log(data);
//                if (data.data.length > 0)
//                {
//                    alert("click like roi");
//                } else
//                {
//                    alert("Bạn chưa click like");
//                }
//            });
//        }, {scope: 'email,publish_actions,user_friends,user_likes'});
//    });



    FB.Event.subscribe('edge.create', function (response) {
        Toast.showWait({text: "Đang xác thực...", width: "130px"});
        var facebook_url = response;
        console.log("Ấn like: ", response);
        FB.getLoginStatus(function (status) {
            console.log("Status login: ", status);
            FB.api('/me', function (info) {
                console.log("Info: ", info);
                $.ajax({
                    type: "get",
                    url: baseurl + "insert-like-fb",
                    timeout: 5000,
                    data: {
                        mac: mac,
                        nasid: nasid,
                        facebook_url: facebook_url,
                        id_campaign: id_campaign,
                        fbid: info.id,
                        email: info.email,
                        fullname: info.name,
                        name_device: name_device,
                        landing_page: landing_page,
                        id_place: id_place,
                        type_time_session: type_time_session
                    },
                    success: function (data) {
                        if (data == '200') {
                            Toast.showMessage({typeMessage: 'success'});
                            setTimeout(function () {
                                Toast.close();
                                Toast.showWait({text: "Truy cập internet...", width: "150px"});
                                location.href = authentication_link;
                            }, 1000);
                        } else {
                            setTimeout(function () {
                                Toast.close();
                                Toast.show({text: "Có lỗi hệ thống."});
                            }, 300);
                        }
                    },
                    error: function () {
                        Toast.close();
                        Toast.show({text: "Xảy ra lỗi, vui lòng thử lại."});
                    }
                });
            });
        });
    });
});
